package com.cn.wanxi.service;

import com.cn.wanxi.model.ProductModel;
import com.sun.org.apache.xpath.internal.SourceTree;

import java.util.ArrayList;
import java.util.List;

public class ProductService {
    /**
     * 封装产品信息到网站首页
     *
     * @return
     */
    public List<ProductModel> getList() {
        List<ProductModel> list = new ArrayList<>();//局部变量
        ProductModel productModel = new ProductModel();
        String imgHrefs[] = productModel.getImgHrefs();
        String titles[] = productModel.getTitles();
        String contents[] = productModel.getContents();
        for (int i = 0; i < imgHrefs.length; i++) {
            ProductModel model = new ProductModel();
            model.setImgHref(imgHrefs[i]);
            model.setTitle(titles[i]);
            model.setContent(contents[i]);
            list.add(model);
        }

        return list;
    }

    public List<ProductModel> getProductListForCompanyJsp() {
        List<ProductModel> list = new ArrayList<>();
        ProductModel productModel = new ProductModel();
        String imgHrefs[] = productModel.getImgHrefsForCompanyJsp();
        for (int i = 0; i < imgHrefs.length; i++) {
            ProductModel model = new ProductModel();
            model.setImgHref(imgHrefs[i]);
            list.add(model);

        }
        return list;
    }

    /**
     * 得到產品展示頁面的产品信息
     * @return
     */
    public List<ProductModel> getProductListForProductJsp() {
        List<ProductModel> list = new ArrayList<>();
        ProductModel productModel = new ProductModel();

        String imgHrefs[] = productModel.getImgHrefsForProductJsp();
        String titles[] = productModel.getTitlesForProductJsp();
        Double prices[] = productModel.getPriceForProductJsp();
        String contetns[] = productModel.getContetnsForProductJsp();
        for (int i = 0; i < imgHrefs.length; i++) {
            ProductModel model = new ProductModel();
            model.setImgHref(imgHrefs[i]);
            model.setTitle(titles[i]);
            model.setContent(contetns[i]);
            model.setPrice(prices[i]);
            list.add(model);
        }
        return list;
    }
}
